# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=ruamel-yaml
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.18.10
pkgrel=1
pkgdesc='YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-ruamel-yaml'
  'purl: pkg:pypi/ruamel-yaml'
  "cpe: cpe:2.3:a:ruamel.yaml_project:ruamel.yaml"
)
msys2_documentation_url='https://yaml.readthedocs.io/'
msys2_issue_tracker_url='https://sourceforge.net/p/ruamel-yaml/tickets/'
url="https://sourceforge.net/projects/ruamel-yaml/"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-ruamel.yaml.clib")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("https://pypi.org/packages/source/${_realname:0:1}/${_realname//-/.}/${_realname//-/.}-${pkgver}.tar.gz"
        0001-setup-add-encoding.patch)
sha256sums=('20c86ab29ac2153f80a428e1254a8adf686d3383df04490514ca3b79a362db58'
            'e0bfac7e9020c2fc2ab101cb3e5836784663baaa1aa2678d7c52496516739b51')

prepare() {
  cd "${_realname//-/.}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-setup-add-encoding.patch"
}

build() {
  cp -r "${_realname//-/.}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
